package com.bluefox.modules.common.log;

import org.springframework.stereotype.Component;

/**
 * @program: bluefox-parent
 * @description:
 * @author: Sun Feng
 * @create: 2020-07-04 10:54
 **/
@Component
public class ThreadUserLog {
    //存储线程对应的用户名日志信息
    private static ThreadLocal<LogComponent> userRecode = new ThreadLocal<LogComponent>();

    /**
     * 添加用户信息
     *
     * @param logComponent
     */
    public void add(LogComponent logComponent) {
        userRecode.set(logComponent);
    }

    /**
     * 记录方法名字和参数
     *
     * @param args
     * @return
     */
    public String reload(String... args) {
        //获取对象
        LogComponent logComponent = userRecode.get();
        //设置数据
        logComponent.supplementLogContent(args);
        return logComponent.toString();
    }

    /**
     * 获取
     * @return
     */
    public LogComponent get() {
        return userRecode.get();
    }

    /**
     * 移除
     */
    public void remove() {
        userRecode.remove();
    }
}
